home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap02 / howto05 / delphi10 / drwsutl2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-13  |  66.2 KB  |  1,766 lines

  1. unit Drwsutl2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22. type
  23.   { This is a descendant of TFileListbox }
  24.   { Which puts icons of files into the   }
  25.   { Objects array rather than the stand- }
  26.   { ard bitmaps.                         }
  27.   TIconFileListBox = class( TFileListBox )
  28.   public
  29.     { public methods and data }
  30.     function GetNextSelection( SourceDirectory : String;
  31.               var CurrentItem : Integer ) : String;
  32.   end;
  33.   TFileWorkBench = class( TComponent )
  34.   public
  35.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  36.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  37.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  38.     function StripNonRootTrailingBackSlash(
  39.               const TheFileName : String ) : String;
  40.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  41.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  42.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  43.                                  TheMessage : String; TheCode : Integer );
  44.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  45.                 TheCode : Integer );
  46.     procedure FMXUCopyFile(const FileName, DestName: String);
  47.     function CopyFile( TargetPath ,
  48.                DestinationPath : String ) : Boolean;
  49.     procedure ChangeTheDirectory( NewPath : String );
  50.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  51.     procedure CopyTheFile( OldPath , NewPath : String );
  52.     procedure MoveTheFile( OldPath , NewPath : String );
  53.     procedure DeleteTheFile( ThePath : String );
  54.     procedure RenameTheFile( OldPath , NewName : String );
  55.     procedure CreateNewDirectory( NewPath : String );
  56.     procedure RemoveDirectory( ThePath : String );
  57.   end;
  58.   TFileIconPanel = class( TPanel )
  59.   private
  60.     { Private declarations }
  61.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  62.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  63.     procedure TheClick( Sender : TObject );   { This holds override click    }
  64.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  65.   protected                                   { event method procedure.      }
  66.     { Protected declarations }
  67.     procedure Paint; override;                { This allows custom painting  }
  68.   public
  69.     { Public declarations }
  70.     FTheIcon : TIcon;                         { This is the display icon    }
  71.     FTheName : String;                        { This is the filename        }
  72.     FTheLabel : TLabel;                       { This is the display label   }
  73.     Selected : Boolean;                       { This holds selection status }
  74.     constructor Create(AOwner : TComponent); override; { override create    }
  75.     procedure Initialize( PanelX              ,             { Left          }
  76.                           PanelY              ,             { Top           }
  77.                           PanelWidth          ,             { Width         }
  78.                           PanelHeight         ,             { Height        }
  79.                           PanelBevelWidth     ,             { Bevel Width   }
  80.                           LabelFontSize         : Integer;  { Font size     }
  81.                           PanelColor          ,             { Main color    }
  82.                           PanelHighlightColor ,             { Bright color  }
  83.                           PanelShadowColor    ,             { Dark color    }
  84.                           LabelTextColor        : TColor;   { Text color    }
  85.                           TheFilename         ,             { Filename      }
  86.                           LabelFontName         : String;   { Font name     }
  87.                           LabelFontStyle        : TFontStyles;  { Font style}
  88.                           ExtraData             : Integer       );  { Drive }
  89.     destructor Destroy; override;             { override destroy to free    }
  90.   end;
  91.   TFileIconPanelScrollBox = class( TScrollBox )
  92.   public
  93.     { Public methods and data }
  94.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  95.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  96.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  97.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  98.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  99.     TheStoredHandle    : HWnd;
  100.     procedure Update;                                { Called to reset display }
  101.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  102.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  103.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  104.     procedure GetColorsForFileIcon( TheFile : String;
  105.                var BC , HC , SC , TC : TColor );
  106.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  107.     function GetNextSelection( SourceDirectory : String;
  108.               var CurrentItem : Integer ) : String;
  109.     procedure DisplayRecursiveSearchResults(
  110.       TheStartingDirectory : String );
  111.   end;
  112.  
  113.   { This procedure gets an icon for a file using FindExecutable  }
  114.   { and ExtractIcon. (assumes file/dir is passed)                }
  115.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  116.   { This procedure spaces out the bitbtn components on a tpanel }
  117.   procedure SpacePanelButtons( WhichPanel : TPanel );
  118.  
  119. implementation
  120. {$R DRWSUTL2.RES}                 { Import custom resource file }
  121.  
  122. { This procedure spaces out the bitbtn components on a tpanel }
  123. procedure SpacePanelButtons( WhichPanel : TPanel );
  124. var TheCalculatedSpacing     ,            { Holds primary spacing }
  125.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  126.     Counter_1                  : Integer; { Loop counter          }
  127.     TotalIBs                   : Integer; { Gets total buttons    }
  128. begin
  129.   { Set up spacing values }
  130.   TotalIBs := WhichPanel.ControlCount;
  131.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  132.    div ( TotalIbs + 1 ));
  133.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  134.   { Loop through all imported buttons and set their Left values }
  135.   for Counter_1 := 1 to WhichPanel.ControlCount do
  136.   begin
  137.     if Counter_1 = 1 then
  138.     begin
  139.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  140.        TheCalculatedSpacing;
  141.     end
  142.     else
  143.     begin
  144.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  145.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  146.     end;
  147.   end;
  148. end;
  149.  
  150. { This procedure gets an icon for a file using FindExecutable  }
  151. { and ExtractIcon. (assumes file/dir is passed)                }
  152. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  153. var TheExt           : String; { File extension holder }
  154.     TheOtherPChar  ,           { Windows ASCIIZ string }
  155.     TheResultPChar ,           { Windows ASCIIZ string }
  156.     ThePChar         : PChar;  { Windows ASCIIZ string }
  157. begin
  158.   { Check for directory and if so get directory icon from RES file }
  159.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  160.   begin
  161.     { Set up the PChar to communicate with Windows }
  162.     GetMem( TheOtherPChar , 255 );
  163.     { Convert Pascal-style string to ASCIIZ Pchar }
  164.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  165.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  166.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  167.     { Release memory from PChar }
  168.     FreeMem( TheOtherPChar , 255 );
  169.     { Leave }
  170.     exit;
  171.   end;
  172.   { Assume archive file; get its extension }
  173.   TheExt := Uppercase( ExtractFileExt( TheName ));
  174.   { If not an executable/image file then use FindExecutable to get icon }
  175.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  176.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  177.   begin
  178.     { Grab three chunks of memory }
  179.     GetMem( TheOtherPChar , 255 );
  180.     GetMem( TheResultPChar , 255 );
  181.     GetMem( ThePChar , 255 );
  182.     { Set up the name and its directory in Windows string formats }
  183.     StrPCopy( ThePChar, TheName );
  184.     StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  185.     { Use FindExecutable API call to get path and name of owning file }
  186.     if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  187.     begin
  188.       { If get a result of 32 or more then try to get first icon of owner }
  189.       { Using ExtractIcon API call; 0 indicates first icon.               }
  190.       TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  191.       { If a handle is 0 then no icon in owner, get default icon from RES file }
  192.       if TheIcon.Handle = 0 then
  193.       begin
  194.         GetMem( TheOtherPChar , 255 );
  195.         StrPCopy( TheOtherPChar , 'NOICON' );
  196.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  197.         FreeMem( TheOtherPChar , 255 );
  198.         exit;
  199.       end;
  200.     end
  201.     else
  202.     { if no assigned executable, then get default icon from RES file }
  203.     begin
  204.       GetMem( TheOtherPChar , 255 );
  205.       StrPCopy( TheOtherPChar , 'NOICON' );
  206.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  207.       FreeMem( TheOtherPChar , 255 );
  208.       exit;
  209.     end;
  210.     FreeMem( TheOtherPChar , 255 );
  211.     FreeMem( TheResultPChar , 255 );
  212.     FreeMem( ThePChar , 255 );
  213.   end
  214.   else
  215.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  216.   begin
  217.     GetMem( ThePChar , 255 );
  218.     StrPCopy( ThePChar , TheName );
  219.     { If no icons in file then get default icon (note use FFFF for -1) }
  220.     if ExtractIcon( hInstance , ThePchar , 65535 ) = 0 then
  221.     begin
  222.       Freemem( ThePChar , 255 );
  223.       GetMem( TheOtherPChar , 255 );
  224.       StrPCopy( TheOtherPChar , 'NOICON' );
  225.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  226.       FreeMem( TheOtherPChar , 255 );
  227.       exit;
  228.     end
  229.     else
  230.     begin
  231.       { Try to get first icon for file }
  232.       TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  233.       FreeMem( ThePChar , 255 );
  234.       { If handle is 0 invalid icon format so use default from RES file }
  235.       if TheIcon.Handle = 0 then
  236.       begin
  237.         GetMem( TheOtherPChar , 255 );
  238.         StrPCopy( TheOtherPChar , 'NOICON' );
  239.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  240.         FreeMem( TheOtherPChar , 255 );
  241.         exit;
  242.       end;
  243.     end;
  244.   end;
  245. end;
  246.  
  247. { This procedure does a fully error-trapped change directory }
  248. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  249. var CurrentDirectory : String;
  250. begin
  251.   if NewPath = '..' then
  252.   begin { Back up one level }
  253.     {$I+}
  254.     try
  255.       { Find the current directory }
  256.       GetDir( 0 , CurrentDirectory );
  257.       { Use EFP to move up one level }
  258.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  259.       { Strip trailing \ if not root }
  260.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  261.       { Try the change to the new drive }
  262.       ChDir( CurrentDirectory );
  263.     except
  264.       { if any exception occurs instantiate exception and show }
  265.       On E:EInOutError do
  266.       begin
  267.         { Call custom error display/lookup procedure }
  268.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  269.          E.Message , E.ErrorCode );
  270.       end;
  271.     end;
  272.   end
  273.   else
  274.   begin { Change to explicit path }
  275.     {$I+}
  276.     try
  277.       { Get target directory path }
  278.       CurrentDirectory := NewPath;
  279.       { Strip trailing \ if not root }
  280.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  281.       { Try the change to the new drive }
  282.       ChDir( CurrentDirectory );
  283.     except
  284.       { if any exception occurs instantiate exception and show }
  285.       On E:EInOutError do
  286.       begin
  287.         { Call custom error display/lookup procedure }
  288.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  289.          E.Message , E.ErrorCode );
  290.       end;
  291.     end;
  292.   end;
  293. end;
  294.  
  295. { This procedure does a fully error-trapped change directory }
  296. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  297. var CurrentDirectory : String;
  298. begin
  299.   {$I+}
  300.   try
  301.     { Find the working directory on new drive }
  302.     GetDir( NewDrive , CurrentDirectory );
  303.     { Try the change to the new drive }
  304.     ChDir( CurrentDirectory );
  305.   except
  306.     { if any exception occurs instantiate exception and show }
  307.     On E:EInOutError do
  308.     begin
  309.       { Call custom error display/lookup procedure }
  310.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  311.        E.Message , E.ErrorCode );
  312.     end;
  313.   end;
  314. end;
  315.  
  316. { This procedure copies a single file with error trapping }
  317. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  318. var AResult : Boolean; { Internal data flag }
  319. begin
  320.   { If Copyfile returns false an error occurred }
  321.   AResult := CopyFile( OldPath , NewPath +
  322.    ExtractFileName( OldPath ));
  323.   { Display meaningful error message }
  324.   if not AResult then HandleDOSError( GlobalErrorType ,
  325.    ExtractFileName( OldPath ) , GlobalError );
  326. end;
  327.  
  328. { This procedure moves a file by copying and delete it }
  329. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  330. var AResult : Boolean; { Internal data flag }
  331.     TheFile : File;    { Use to get errors  }
  332. begin
  333.   { If Copyfile returns false an error occurred }
  334.   AResult := CopyFile( OldPath , NewPath +
  335.     ExtractFileName( OldPath ));
  336.   { Display meaningful error message }
  337.   if not AResult then HandleDOSError( GlobalErrorType ,
  338.    ExtractFileName( OldPath ), GlobalError );
  339.   { After valid copying, delete source file }
  340.   {$I+}
  341.   if AResult then try
  342.     { Use this trick to get valid exception handling }
  343.     AssignFile( TheFile , OldPath );
  344.     { Use erase because Deletefile doesn't give exceptions! }
  345.     Erase( TheFile );
  346.   except
  347.     { if any exception occurs instantiate exception and show }
  348.     On E:EInOutError do
  349.     begin
  350.       { Call custom error display/lookup procedure }
  351.       HandleIOException( EOC_DELETEFILE , ExtractFileName( OldPath ) ,
  352.        E.Message , E.ErrorCode );
  353.     end;
  354.   end;
  355. end;
  356.  
  357. { This procedure safely deletes a single file }
  358. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  359. var TheFile : File; { Internal file handle }
  360. begin
  361.   {$I+}
  362.   try
  363.     { Use this trick to get valid exception handling }
  364.     AssignFile( TheFile , ThePath );
  365.     { Use erase because Deletefile doesn't give exceptions! }
  366.     Erase( TheFile );
  367.   except
  368.     { if any exception occurs instantiate exception and show }
  369.     On E:EInOutError do
  370.     begin
  371.       { Call custom error display/lookup procedure }
  372.       HandleIOException( EOC_DELETEFILE , ExtractFileName( ThePath ) ,
  373.        E.Message , E.ErrorCode );
  374.     end;
  375.   end;
  376. end;
  377.  
  378. { This procedure renames a file with full error trapping }
  379. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  380. var TheFile : File; { Internal file handle }
  381. begin
  382.   {$I+}
  383.   try
  384.     { Use this trick to get valid exception handling }
  385.     AssignFile( TheFile , OldPath );
  386.     { Use this because RenameFile doesn't give exceptions! }
  387.     Rename( TheFile , NewName );
  388.   except
  389.     { if any exception occurs instantiate exception and show }
  390.     On E:EInOutError do
  391.     begin
  392.       { Call custom error display/lookup procedure }
  393.       HandleIOException( EOC_RENAMEFILE , ExtractFileName( OldPath ) ,
  394.        E.Message , E.ErrorCode );
  395.     end;
  396.   end;
  397. end;
  398.  
  399. { This procedure creates a new directory with full error trapping }
  400. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  401. begin
  402.   {$I+}
  403.   try
  404.     Mkdir( NewPath );
  405.   except
  406.     { if any exception occurs instantiate exception and show }
  407.     On E:EInOutError do
  408.     begin
  409.       { Call custom error display/lookup procedure }
  410.       HandleIOException( EOC_MAKEDIR , ExtractFileName( NewPath ) ,
  411.        E.Message , E.ErrorCode );
  412.     end;
  413.   end;
  414. end;
  415.  
  416. { This procedure remove a directory with full error trapping }
  417. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  418. begin
  419.   {$I+}
  420.   try
  421.     Rmdir( ThePath );
  422.   except
  423.     { if any exception occurs instantiate exception and show }
  424.     On E:EInOutError do
  425.     begin
  426.       { Call custom error display/lookup procedure }
  427.       HandleIOException( EOC_DELETEDIR , ExtractFileName( ThePath ) ,
  428.        E.Message , E.ErrorCode );
  429.     end;
  430.   end;
  431. end;
  432.  
  433. { This is a generic copy routine taken from Delphi sample code }
  434. { It has been edited to return viable error codes!             }
  435. procedure TFileWorkBench.FMXUCopyFile(const FileName, DestName: String);
  436. var
  437.   CopyBuffer: Pointer; { buffer for copying }
  438.   BytesCopied: Longint;
  439.   TheAttr : Integer;
  440.   Source, Dest: Integer; { handles }
  441. const
  442.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  443. begin
  444.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  445.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  446.   if Source < 0 then
  447.   begin  { error creating source file }
  448.     GlobalErrorType := EOC_SOURCECOPY;
  449.     GlobalError := -IOResult;
  450.     if GlobalError = 0 then GlobalError := -157;
  451.     FreeMem( CopyBuffer, ChunkSize );
  452.     exit;
  453.   end;
  454.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  455.   if Dest < 0 then
  456.   begin  { error creating destination file }
  457.     FileClose( Source );
  458.     GlobalErrorType := EOC_DESTCOPY;
  459.     GlobalError := -IOResult;
  460.     if GlobalError = 0 then GlobalError := -159;
  461.     FreeMem( CopyBuffer , ChunkSize );
  462.     exit;
  463.   end;
  464.   {$I-}
  465.   repeat
  466.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  467.     if BytesCopied > 0 then { if we read anything... }
  468.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  469.   until BytesCopied < ChunkSize; { until we run out of chunks }
  470.   {$I+}
  471.   GlobalError := -IOResult;  { get any error code which happens during copying }
  472.   FileClose(Dest); { close the destination file }
  473.   FileClose(Source); { close the source file }
  474.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  475. end;
  476.  
  477. { This function calls the sample Copy code and handles errors }
  478. function TFileWorkBench.CopyFile( TargetPath ,
  479.           DestinationPath : String ) : Boolean;
  480. begin
  481.   { Set global error value to no error }
  482.   GlobalError := 0;
  483.   { Call the sample procedure to do the copy }
  484.   FMXUCopyFile( TargetPath, DestinationPath );
  485.   { If no error return true else return false }
  486.   if GlobalError < 0 then CopyFile := false else
  487.    CopyFile := true;
  488. end;
  489.  
  490. { This procedure handles displaying a user-friendly Dialog box with a }
  491. { Message for Delphi IO exception errors.                             }
  492. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  493.            ThePath : String; TheMessage : String; TheCode : Integer );
  494. var ErrorMessageString : String;  { Holds internal data }
  495.     OperationString    : String;  { Holds internal data }
  496. begin
  497.   { clear to check for unrecognized code }
  498.   ErrorMessageString := '';
  499.   { Check against imported code }
  500.   case TheCode of
  501.     2    : ErrorMessageString := 'File not found';
  502.     3    : ErrorMessageString := 'Path not found';
  503.     4    : ErrorMessageString := 'Too many open files';
  504.     5    : ErrorMessageString := 'File access denied';
  505.     6    : ErrorMessageString := 'Invalid file handle';
  506.     12    : ErrorMessageString := 'Invalid file access code';
  507.     15    : ErrorMessageString := 'Invalid drive number';
  508.     16  : ErrorMessageString := 'Cannot remove current directory';
  509.     17    : ErrorMessageString := 'Cannot rename across drives';
  510.     100    : ErrorMessageString := 'Disk read error';
  511.     101    : ErrorMessageString := 'Disk write error';
  512.     102    : ErrorMessageString := 'File not assigned';
  513.     103    : ErrorMessageString := 'File not open';
  514.     104    : ErrorMessageString := 'File not open for input';
  515.     105    : ErrorMessageString := 'File not open for output';
  516.   end;
  517.   case TheOpCode of
  518.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  519.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  520.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  521.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  522.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  523.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  524.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  525.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  526.   end;
  527.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  528.   if ErrorMessageString = '' then
  529.   begin
  530.     Screen.Cursor := crDefault;
  531.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  532.      TheMessage , mtError , [mbOK],0);
  533.   end
  534.   else
  535.   begin
  536.     { Recognized DOS exception, reset cursor for neatness }
  537.     Screen.Cursor := crDefault;
  538.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  539.      ErrorMessageString , mtError , [mbOK], 0 );
  540.   end;
  541. end;
  542.  
  543. { This procedure handles displaying a user-friendly Dialog box with a }
  544. { Message for DOS error codes.                                        }
  545. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  546.            ThePath : String;  TheCode : Integer );
  547. var ErrorMessageString : String;  { internal message holder }
  548.     OperationString : String;     { internal message holder }
  549. begin
  550.   { clear the message holder to check for unrecognized code }
  551.   ErrorMessageString := '';
  552.   { Negate the code back to normal number and check to set string }
  553.   case -TheCode of
  554.     2    : ErrorMessageString := 'File not found';
  555.     3    : ErrorMessageString := 'Path not found';
  556.     4    : ErrorMessageString := 'Too many open files';
  557.     5    : ErrorMessageString := 'File access denied';
  558.     6    : ErrorMessageString := 'Invalid file handle';
  559.     12    : ErrorMessageString := 'Invalid file access code';
  560.     15    : ErrorMessageString := 'Invalid drive number';
  561.     16  : ErrorMessageString := 'Cannot remove current directory';
  562.     17    : ErrorMessageString := 'Cannot rename across drives';
  563.     100    : ErrorMessageString := 'Disk read error';
  564.     101    : ErrorMessageString := 'Disk write error';
  565.     102    : ErrorMessageString := 'File not assigned';
  566.     103    : ErrorMessageString := 'File not open';
  567.     104    : ErrorMessageString := 'File not open for input';
  568.     105    : ErrorMessageString := 'File not open for output';
  569.     157 : ErrormessageString := 'Could not open Source File';
  570.     159 : ErrormessageString := 'Could not open Target File';
  571.   end;
  572.   case TheOpCode of
  573.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  574.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  575.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  576.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  577.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  578.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  579.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  580.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  581.   end;
  582.   { If the string is empty an unrecognized code was sent in }
  583.   if ErrorMessageString = '' then
  584.   begin
  585.     { Sent up db based on source or target error; reset cursor for neatness }
  586.     Screen.Cursor := crDefault;
  587.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  588.      IntToStr( TheCode ) , mtError , [mbOK],0);
  589.   end
  590.   else  { Code is recognized, use message from case statement }
  591.   begin
  592.     { Format the output for source or target error }
  593.     Screen.Cursor := crDefault;
  594.     MessageDlg( OperationString + ExtractFilePath( ThePath ) + ' ' +
  595.      ErrorMessageString , mtError , [mbOK], 0 );
  596.   end;
  597. end;
  598.  
  599. { This procedure sets the imported booleans to the file's attributes }
  600. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  601.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  602.             IsSysFile : Boolean );
  603. var TheResult : Integer; { Traps for error code on VolumeID }
  604. begin
  605.   { Clear the imported flags for default }
  606.   IsDirectory := false;
  607.   IsArchive := false;
  608.   IsVolumeID := false;
  609.   IsHidden := False;
  610.   IsReadOnly := false;
  611.   IsSysFile := false;
  612.   { Make the Dos call }
  613.   TheResult := FileGetAttr( TheFile );
  614.   if TheResult < 0 then
  615.   begin
  616.     { Volume ID returns -2 (?) }
  617.     IsVolumeID := true;
  618.     { It has no other properties }
  619.     exit;
  620.   end;
  621.   { Use AND test to set all other properties }
  622.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  623.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  624.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  625.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  626.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  627.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  628. end;
  629.  
  630. { This function makes sure a pathname has a trailing \ }
  631. function TFileWorkBench.ForceTrailingBackSlash(
  632.           const TheFileName : String ) : String;
  633. var TempString : String;  { Used to hold function result }
  634. begin
  635.   { If no trailing \ add one (root will already have one.) }
  636.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  637.    TempString := TheFileName + '\' else TempString := TheFileName;
  638.   { Return modified or non-modified string }
  639.   ForceTrailingBackslash := TempString;
  640. end;
  641.  
  642. { This function makes sure a non-root dir has no trailing \ }
  643. function TFileWorkBench.StripNonRootTrailingBackSlash(
  644.           const TheFileName : String ) : String;
  645. var TempString : String ; { Used to hold function result }
  646. begin
  647.   { Default is no change }
  648.   TempString := TheFileName;
  649.   { If not root then }
  650.   if Length( TheFileName ) > 3 then
  651.   begin
  652.     { If has a trailing backslash remove it }
  653.     if TheFileName[ Length( TheFileName )] = '\' then
  654.     begin
  655.       TempString := Copy( TheFileName , 1 ,
  656.        Length( TheFileName ) - 1 );
  657.     end;
  658.   end;
  659.   { Export the final result }
  660.   StripNonRootTrailingBackSlash := TempString;
  661. end;
  662.  
  663. { This gets the next selected listbox item }
  664. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  665.           var CurrentItem : Integer ): String;
  666. var TheResult : String;  { Internal storage }
  667.     finished  : boolean; { Loop flag        }
  668. begin
  669.   { If out of items to check signal and exit }
  670.   if CurrentItem > Items.Count then TheResult := '' else
  671.   begin
  672.     { Otherwise scan from current position till match or end }
  673.     finished := false;
  674.     while not finished do
  675.     begin
  676.       { Check against selected property }
  677.       if Selected[ CurrentItem - 1 ] then
  678.       begin
  679.         { If selected then return it and abort loop }
  680.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  681.         finished := true;
  682.         { Increment current position }
  683.         CurrentItem := CurrentItem + 1;
  684.      end
  685.       else
  686.       begin
  687.         { Increment current position }
  688.         CurrentItem := CurrentItem + 1;
  689.         { Otherwise check for end of data and abort if out of entries }
  690.         if CurrentItem > Items.Count then
  691.         begin
  692.           TheResult := '';
  693.           finished := true;
  694.         end;
  695.       end;
  696.     end;
  697.   end;
  698.   { Return stored result }
  699.   GetNextSelection := TheResult;
  700. end;
  701.  
  702. { Create method for FIP                                }
  703. constructor TFileIconPanel.Create( AOwner : TComponent );
  704. begin
  705.   { call inherited -- VITAL! }
  706.   inherited Create( AOwner );
  707.   { create icon and label components, making self owner/displayer }
  708.   FTheIcon := TIcon.Create;
  709.   FTheLabel := TLabel.Create( Self );
  710.   FThelabel.Parent := Self;
  711.   { Set own and labels mouse methods to stored methods }
  712.   OnClick := TheClick;
  713.   OnDblClick := TheDblClick;
  714.   FTheLabel.OnClick := TheClick;
  715.   FTheLabel.OnDblClick := TheDblClick;
  716.   { Set alignment and autosize properties of the label }
  717.   FTheLabel.Autosize := false;
  718.   FTheLabel.Alignment := taCenter;
  719.   { Set selected to false }
  720.   Selected := false;
  721. end;
  722.  
  723. { Initialization method for FIP                                         }
  724. procedure TFileIconPanel.Initialize( PanelX              ,
  725.                                      PanelY              ,
  726.                                      PanelWidth          ,
  727.                                      PanelHeight         ,
  728.                                      PanelBevelWidth     ,
  729.                                      LabelFontSize         : Integer;
  730.                                      PanelColor          ,
  731.                                      PanelHighlightColor ,
  732.                                      PanelShadowColor    ,
  733.                                      LabelTextColor        : TColor;
  734.                                      TheFilename         ,
  735.                                      LabelFontName         : String;
  736.                                      LabelFontStyle        : TFontStyles;
  737.                                      ExtraData             : Integer );
  738.  
  739. var TheLabelHeight ,             { Holder for label pixel height }
  740.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  741.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  742. begin
  743.   { Set the basic properties based on imported parameters }
  744.   Left := PanelX;
  745.   Top := PanelY;
  746.   Width := PanelWidth;
  747.   Height := PanelHeight;
  748.   Color := PanelColor;
  749.   BevelWidth := PanelBevelWidth;
  750.   FHighlightColor := PanelHighlightColor;
  751.   FShadowColor := PanelShadowColor;
  752.   FTheName := TheFilename;
  753.   { If the ExtraData field is non-0 then a drive is being sent in }
  754.   if ExtraData <> 0 then
  755.   begin
  756.     { Use the data field value to determine which icon to get from RES file }
  757.     case ExtraData of
  758.       1 : begin
  759.             GetMem( TheOtherPChar , 255 );
  760.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  761.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  762.             FreeMem( TheOtherPChar , 255 );
  763.           end;
  764.       2 : begin
  765.             GetMem( TheOtherPChar , 255 );
  766.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  767.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  768.             FreeMem( TheOtherPChar , 255 );
  769.           end;
  770.       3 : begin
  771.             GetMem( TheOtherPChar , 255 );
  772.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  773.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  774.             FreeMem( TheOtherPChar , 255 );
  775.           end;
  776.       4 : begin
  777.             GetMem( TheOtherPChar , 255 );
  778.             StrPCopy( TheOtherPChar , 'CDROM' );
  779.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  780.             FreeMem( TheOtherPChar , 255 );
  781.           end;
  782.       5 : begin
  783.             GetMem( TheOtherPChar , 255 );
  784.             StrPCopy( TheOtherPChar , 'RAM' );
  785.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  786.             FreeMem( TheOtherPChar , 255 );
  787.           end;
  788.     end;
  789.     { The FileNme property is already set up for the caption; use directly }
  790.     FTheLabel.Caption := TheFilename;
  791.     { Set up the hint for later use (make sure to set ShowHint) }
  792.     Hint := 'Change to ' + TheFileName;
  793.     ShowHint := true;
  794.     { Set up all imported label properties and center it for drawing }
  795.     with FTheLabel do
  796.     begin
  797.       Font.Name := LabelFontName;
  798.       Font.Size := LabelFontSize;
  799.       Font.Style := LabelFontStyle;
  800.       Font.Color := LabelTextColor;
  801.       Canvas.Brush.Color := PanelColor;
  802.       Canvas.Font := Font;
  803.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  804.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  805.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  806.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  807.       Top := Top + Round( Self.Height * 0.75 );
  808.       Height := TheLabelHeight;
  809.       Width := TheLabelWidth;
  810.     end;
  811.   end
  812.   else
  813.   begin
  814.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  815.     { icon either from the file, its owner, or a RES file default.          }
  816.     GetIconForFile( FTheName , FTheIcon );
  817.     { Check for the Backup caption and set it specially }
  818.     if ExtractfileName( FThename ) = '..' then
  819.     begin
  820.       FTheLabel.Caption := '..';
  821.       Hint := 'Up One Level';
  822.     end
  823.     else
  824.     begin
  825.       { Otherwise just get the filename for the label caption }
  826.       { And the full path for the hint (used later.)          }
  827.       FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  828.       Hint := FTheName;
  829.     end;
  830.     { Activate showhint so hints are seen }
  831.     ShowHint := true;
  832.     { Set label properties with imported values and center for display }
  833.     with FTheLabel do
  834.     begin
  835.       Font.Name := LabelFontName;
  836.       Font.Size := LabelFontSize;
  837.       Font.Style := LabelFontStyle;
  838.       Font.Color := LabelTextColor;
  839.       Canvas.Brush.Color := PanelColor;
  840.       Canvas.Font := Font;
  841.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  842.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  843.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  844.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  845.       Top := Top + Round( Self.Height * 0.75 );
  846.       Height := TheLabelHeight;
  847.       Width := TheLabelWidth;
  848.     end;
  849.   end;
  850. end;
  851.  
  852. { Destroy method for FIP }
  853. destructor TFileIconPanel.Destroy;
  854. begin
  855.   { free component resources }
  856.   FTheIcon.Free;
  857.   FTheLabel.Free;
  858.   { call inherited -- VITAL! }
  859.   inherited Destroy;
  860. end;
  861.  
  862. { TheClick method for FIP; used for event responses }
  863. procedure TFileIconPanel.TheClick( Sender : TObject );
  864. begin
  865.   { Currently ignore drive clicks }
  866.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  867.   { Flip status of bevels }
  868.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  869.    BevelOuter := bvRaised;
  870.   { Flip selected variable }
  871.   Selected := not Selected;
  872.   { Set redisplay }
  873.   Invalidate;
  874. end;
  875.  
  876. { TheDblClick method for FIP; used for event responses }
  877. procedure TFileIconPanel.TheDblClick( Sender : TObject );
  878. var CurrentDirectory : String;    { Use to store dirs }
  879.     TheDrive         : String;    { Get drive letter  }
  880.     WhichDrive       : Integer;   { Get drive number  }
  881.     ErrorCheck       : Integer;
  882.     TheFWB           : TFileWorkBench;
  883. begin
  884.   { Create FileWorkBench for later use }
  885.   TheFWB := TFileWorkBench.Create( Self );
  886.   { Check for label or FIP sender }
  887.   if Sender is TFileIconPanel then
  888.   begin
  889.     if FTheLabel.Caption = '..' then
  890.     begin { deal with backup request }
  891.       { Change to new directory }
  892.       TheFWB.ChangeTheDirectory( '..' );
  893.       { Call special method due to SendMessage problem! }
  894.       TFileIconPanelScrollBox( Parent ).Update;
  895.     end
  896.     else
  897.     begin
  898.       { Check for DRIVE id in name }
  899.       if Pos( 'DRIVE' , FTheName ) <> 0 then
  900.       begin { Double Click on a Drive Icon }
  901.         { Pull out the letter from name }
  902.         TheDrive := Copy( FtheName , 7 , 1 );
  903.         { Convert it to a number }
  904.         WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  905.         TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  906.         { Call special method due to SendMessage problem! }
  907.         TFileIconPanelScrollBox( Parent ).Update;
  908.       end
  909.       else
  910.       begin { Double click on a dir/file icon }
  911.         if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  912.         begin { A directory, change to it }
  913.           { Since full path in name, simply change to it! }
  914.           TheFWB.ChangeTheDirectory( FTheName );
  915.           { Call special method due to SendMessage problem! }
  916.           TFileIconPanelScrollBox( Parent ).Update;
  917.         end
  918.         else
  919.         begin { A file; attempt to shellexecute it }
  920.           { Call shellexec as a wrapper around ShellExecute API call }
  921.           { False indicates failure, signal error                    }
  922.           if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  923.            then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  924.             [mbOK], 0);
  925.         end;
  926.       end;
  927.     end;
  928.   end
  929.   else
  930.   begin
  931.     with Sender as TLabel do
  932.     begin
  933.       if Caption = '..' then
  934.       begin { Deal with backup request }
  935.         { Change to new directory }
  936.         TheFWB.ChangeTheDirectory( '..' );
  937.         { Call special method due to SendMessage problem! }
  938.         TFileIconPanelScrollBox( Parent ).Update;
  939.       end
  940.       else
  941.       begin
  942.         with Parent as TFileIconPanel do
  943.         begin
  944.           { Check for DRIVE id in name }
  945.           if Pos( 'DRIVE' , FTheName ) <> 0 then
  946.           begin { Double Click on a Drive Icon }
  947.             { Pull out the letter from name }
  948.             TheDrive := Copy( FtheName , 7 , 1 );
  949.             { Convert it to a number }
  950.             WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  951.             { Call the method to change to default dir on new drive }
  952.             TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  953.             { Call special method due to SendMessage problem! }
  954.             TFileIconPanelScrollBox( Parent ).Update;
  955.           end
  956.           else
  957.           begin { Double click on a dir/file icon }
  958.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  959.             begin { A directory, change to it }
  960.               { Since full path in name, simply change to it! }
  961.               TheFWB.ChangeTheDirectory( FTheName );
  962.               { Call special method due to SendMessage problem! }
  963.               TFileIconPanelScrollBox( Parent ).Update;
  964.             end
  965.             else
  966.             begin { A file; attempt to shellexecute it }
  967.               { Call shellexec as a wrapper around ShellExecute API call }
  968.               { False indicates failure, signal error                    }
  969.               if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL ,
  970.                false ) then MessageDlg('Could not Shell out to ' + FTheName ,
  971.                 mtError, [mbOK], 0);
  972.             end;
  973.           end;
  974.         end;
  975.       end;
  976.     end;
  977.   end;
  978.   TheFWB.Free; { This prevents resource leak }
  979. end;
  980.  
  981. { Paint method for FIP; overrides normal paint }
  982. procedure TFileIconPanel.Paint;
  983. var
  984.   TheOtherRect   : TRect;   { Holds clientrect   }
  985.   TopColor     ,            { Holds bright color }
  986.   BottomColor    : TColor;  { Holds dark color   }
  987.  
  988. { These methods are from Borland Intl., copyright 1995 }
  989. procedure Frame3D(    Canvas       : TCanvas;
  990.                   var TheRect      : TRect;
  991.                       TopColor   ,
  992.                       BottomColor  : TColor;
  993.                       Width        : Integer );
  994.  
  995. procedure DoRect;
  996. var
  997.   TopRight, BottomLeft: TPoint;
  998. begin
  999.   with Canvas, TheRect do
  1000.   begin
  1001.     TopRight.X := Right;
  1002.     TopRight.Y := Top;
  1003.     BottomLeft.X := Left;
  1004.     BottomLeft.Y := Bottom;
  1005.     Pen.Color := TopColor;
  1006.     PolyLine([BottomLeft, TopLeft, TopRight]);
  1007.     Pen.Color := BottomColor;
  1008.     Dec(BottomLeft.X);
  1009.     PolyLine([TopRight, BottomRight, BottomLeft]);
  1010.   end;
  1011. end;
  1012.  
  1013. begin
  1014.   Canvas.Pen.Width := 1;
  1015.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  1016.   while Width > 0 do
  1017.   begin
  1018.     Dec(Width);
  1019.     DoRect;
  1020.     InflateRect(TheRect, -1, -1);
  1021.   end;
  1022.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  1023. end;
  1024.  
  1025. procedure AdjustColors(Bevel: TPanelBevel);
  1026. begin
  1027.   TopColor := FHighlightColor;
  1028.   if Bevel = bvLowered then TopColor := FShadowColor;
  1029.   BottomColor := FShadowColor;
  1030.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  1031. end;
  1032.  
  1033. { Custom code begins here }
  1034. begin
  1035.   { Get the rectangle of the control with API/method call }
  1036.   TheOtherRect := GetClientRect;
  1037.   { draw basic rectangle with basic color }
  1038.   with Canvas do
  1039.   begin
  1040.     Brush.Color := Color;
  1041.     FillRect(TheOtherRect);
  1042.   end;
  1043.   { Set up for top "icon" frame  and draw it with frame3d }
  1044.   TheOtherRect.Right := Width;
  1045.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  1046.   if BevelOuter <> bvNone then
  1047.   begin
  1048.     AdjustColors(BevelOuter);
  1049.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1050.   end;
  1051.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1052.   if BevelInner <> bvNone then
  1053.   begin
  1054.     AdjustColors(BevelInner);
  1055.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1056.   end;
  1057.   { Do the same for the lower "label" frame }
  1058.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  1059.   TheOtherRect.Left := 0;
  1060.   TheOtherRect.Bottom := Height;
  1061.   TheOtherRect.Right := Width;
  1062.   if BevelOuter <> bvNone then
  1063.   begin
  1064.     AdjustColors(BevelOuter);
  1065.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1066.   end;
  1067.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  1068.   if BevelInner <> bvNone then
  1069.   begin
  1070.     AdjustColors(BevelInner);
  1071.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  1072.   end;
  1073.   { Then draw the icon using canvas draw method }
  1074.   Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  1075.   ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  1076. end;
  1077.  
  1078. { This procedure clears a scrollbox of all FileIconPanels }
  1079. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  1080. var Counter_1 : Integer;
  1081.     TheComponent : TComponent;
  1082. begin
  1083.   { Note that must use while loop since component count continually }
  1084.   { decreases as removes are made!                                  }
  1085.   while ComponentCount > 0 do
  1086.   begin
  1087.     { Save the component as a generic TComponent }
  1088.     TheComponent := Components[ 0 ];
  1089.     { Call removecomponent to pull it out of the owner list for sb }
  1090.     { This avoids GPF when freeing the sb.                         }
  1091.     RemoveComponent( Components[ 0 ]);
  1092.     { Typecast the pointer and free it to release memory and res. }
  1093.     TFileIconPanel( TheComponent ).Free;
  1094.   end;
  1095. end;
  1096.  
  1097. { This procedure scans for drives and obtains their type and creates file }
  1098. { icon panels to represent them.                                          }
  1099. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  1100.            YCounter : Integer );
  1101. type
  1102.   { This if from filectrl unit; reproduce here for completeness }
  1103.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  1104.                 dtRAM);
  1105. var
  1106.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  1107.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  1108.   DriveChar       : Char;            { Used to hold drive letter           }
  1109.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  1110.   Finished        : Boolean;         { Loop flag                           }
  1111.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  1112.   ButtonColor   ,                    { Main panel color                    }
  1113.   ButtonHLColor ,                    { Bright panel color                  }
  1114.   ButtonSColor  ,                    { Dark panel color                    }
  1115.   Textcolor       : TColor;          { Label text color                    }
  1116.  
  1117. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1118. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  1119. {  and the drive is using a CD driver                                   }
  1120.  
  1121. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  1122. asm
  1123.   MOV   AX,1500h { look for MSCDEX }
  1124.   XOR   BX,BX
  1125.   INT   2fh
  1126.   OR    BX,BX
  1127.   JZ    @Finish
  1128.   MOV   AX,150Bh { check for using CD driver }
  1129.   MOV   CX,DriveNum
  1130.   INT   2fh
  1131.   OR    AX,AX
  1132.   @Finish:
  1133. end;
  1134.  
  1135. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1136. { Check whether drive is a RAM drive.                                   }
  1137. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  1138. var
  1139.   TempResult: Boolean;
  1140. asm
  1141.   MOV   TempResult,False
  1142.   PUSH  DS
  1143.   MOV   BX,SS
  1144.   MOV   DS,BX
  1145.   SUB   SP,0200h
  1146.   MOV   BX,SP
  1147.   MOV   AX,DriveNum
  1148.   MOV   CX,1
  1149.   XOR   DX,DX
  1150.   INT   25h  { read boot sector }
  1151.   ADD   SP,2
  1152.   JC    @ItsNot
  1153.   MOV   BX,SP
  1154.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  1155.   JNE   @ItsNot
  1156.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  1157.   JNE   @ItsNot
  1158.   MOV   TempResult,True
  1159.   @ItsNot:
  1160.   ADD   SP,0200h
  1161.   POP   DS
  1162.   MOV   AL, TempResult
  1163. end;
  1164.  
  1165. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  1166. { Finds the type of a drive letter.                                     }
  1167. function FindDriveType(DriveNum: Integer): TDriveType;
  1168. begin
  1169.   Result := TDriveType(GetDriveType(DriveNum));
  1170.   if (Result = dtFixed) or (Result = dtNetwork) then
  1171.   begin
  1172.     if IsCDROM(DriveNum) then Result := dtCDROM
  1173.     else if (Result = dtFixed) then
  1174.     begin
  1175.         { do not check for RAMDrive under Windows NT }
  1176.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  1177.         Result := dtRAM;
  1178.     end;
  1179.   end;
  1180. end;
  1181.  
  1182. begin
  1183.   { Set the button colors to an aquamarine color scheme for drives }
  1184.   ButtonColor := clTeal;
  1185.   ButtonHLColor := clAqua;
  1186.   ButtonSColor := clNavy;
  1187.   TextColor := clblack;
  1188.   { Set initial variables before looping for all drives }
  1189.   finished := false;
  1190.   DriveNum := 0;
  1191.   while not finished do
  1192.   begin
  1193.     { Start with no drive found }
  1194.     IconType := 0;
  1195.     { Call the Borland method to get the drive info }
  1196.     DriveType := FindDriveType(DriveNum);
  1197.     { Set its letter and make it uppercase }
  1198.     DriveChar := Chr(DriveNum + ord('a'));
  1199.     DriveChar := Upcase(DriveChar);
  1200.     { Assign an icon based on the drive type; if no drive exists type is nil }
  1201.     case DriveType of
  1202.       dtFloppy  : IconType := 1;
  1203.       dtFixed   : IconType := 2;
  1204.       dtNetwork : IconType := 3;
  1205.       dtCDROM   : IconType := 4;
  1206.       dtRAM     : IconType := 5;
  1207.     end;
  1208.     { Set to check next drive letter }
  1209.     DriveNum := DriveNum + 1;
  1210.     { But if no match then out of drives so set exit flag }
  1211.     if IconType = 0 then finished := true;
  1212.     { If drive was valid then set up the new FileIconPanel on the imported }
  1213.     { Scrollbox                                                            }
  1214.     if not finished then
  1215.     begin
  1216.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  1217.       TheFIP := TFileIconPanel.Create( Self );
  1218.       TheFIP.Parent := Self;
  1219.       { Call its initialize method with imported position values and the   }
  1220.       { preset color scheme, a drive caption, and a minimum font. Note the }
  1221.       { setting of the ExtraData field to non-zero; this signals a drive   }
  1222.       { rather than a file being sent in.                                  }
  1223.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1224.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1225.         7 , ButtonColor, ButtonHLColor,
  1226.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  1227.        IconType );
  1228.       { Increment the column counter; if it exceeds max move to new row      }
  1229.       { Note that these are 'var' parameters and will export final position. }
  1230.       XCounter := XCounter + 1;
  1231.       if XCounter > MaxIconsInARow then
  1232.       begin
  1233.         XCounter := 1;
  1234.         YCounter := YCounter + 1;
  1235.       end;
  1236.     end;
  1237.   end;
  1238. end;
  1239.  
  1240. { This procedure assigns colors to FIP's based on file attributes }
  1241. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  1242.            var BC , HC , SC , TC : TColor );
  1243. var AmADir      ,             { Booleans hold file attribs }
  1244.     AmAnArchive ,
  1245.     AmAVolumeId ,
  1246.     AmHidden    ,
  1247.     AmReadOnly  ,
  1248.     AmSystem      : Boolean;
  1249. begin
  1250.   { Make the call to internal fileworkbench to set attributes }
  1251.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  1252.    AmHidden , AmReadOnly , AmSystem );
  1253.   { Volume ID has no subtypes }
  1254.   if AmAVolumeID then
  1255.   begin
  1256.     BC := clOlive;
  1257.     HC := clYellow;
  1258.     SC := clBlack;
  1259.     TC := clWhite;
  1260.     exit;
  1261.   end;
  1262.   { Check all directory combinations }
  1263.   if AmADir then
  1264.   begin
  1265.     BC := clNavy;
  1266.     HC := clBlue;
  1267.     SC := clBlack;
  1268.     TC := clWhite;
  1269.     if AmHidden then
  1270.     begin
  1271.       if AmReadOnly then
  1272.       begin
  1273.         if AmSystem then
  1274.         begin { One HECK of a file! }
  1275.           BC := clBlack;
  1276.           HC := clSilver;
  1277.           SC := clGray;
  1278.           TC := clWhite;
  1279.         end
  1280.         else
  1281.         begin { Dir,RO,Hid }
  1282.           BC := clMaroon;
  1283.           HC := clFuchsia;
  1284.           SC := clGreen;
  1285.           TC := clWhite;
  1286.         end;
  1287.       end
  1288.       else
  1289.       begin { Dir,Hid }
  1290.         BC := clPurple;
  1291.         HC := clFuchsia;
  1292.         SC := clBlack;
  1293.         TC := clWhite;
  1294.       end;
  1295.     end
  1296.     else
  1297.     begin
  1298.       if AmReadOnly then
  1299.       begin
  1300.         if AmSystem then
  1301.         begin { Dir,RO,Sys }
  1302.           BC := clMaroon;
  1303.           HC := clLime;
  1304.           SC := clGreen;
  1305.           TC := clWhite;
  1306.         end
  1307.         else
  1308.         begin { Dir,RO }
  1309.           BC := clGreen;
  1310.           HC := clLime;
  1311.           SC := clBlack;
  1312.           TC := clWhite;
  1313.         end;
  1314.       end
  1315.       else
  1316.       begin
  1317.         if AmSystem then
  1318.         begin { Dir,Sys }
  1319.           BC := clMaroon;
  1320.           HC := clRed;
  1321.           SC := clBlack;
  1322.           TC := clWhite;
  1323.         end;
  1324.       end;
  1325.     end;
  1326.   end
  1327.   else { Archive Only; check all combinations }
  1328.   begin
  1329.     BC := clSilver;
  1330.     HC := clWhite;
  1331.     SC := clGray;
  1332.     TC := clBlack;
  1333.     if AmHidden then
  1334.     begin
  1335.       if AmReadOnly then
  1336.       begin
  1337.         if AmSystem then
  1338.         begin { Hid,RO,Sys }
  1339.           BC := clRed;
  1340.           HC := clLime;
  1341.           SC := clPurple;
  1342.           TC := clBlack;
  1343.         end
  1344.         else
  1345.         begin { RO,Hid }
  1346.           BC := clLime;
  1347.           HC := clFuchsia;
  1348.           SC := clMaroon;
  1349.           TC := clBlack;
  1350.         end;
  1351.       end
  1352.       else
  1353.       begin { Hid }
  1354.         BC := clFuchsia;
  1355.         HC := clWhite;
  1356.         SC := clPurple;
  1357.         TC := clBlack;
  1358.       end;
  1359.     end
  1360.     else
  1361.     begin
  1362.       if AmReadOnly then
  1363.       begin
  1364.         if AmSystem then
  1365.         begin { RO,Sys }
  1366.           BC := clRed;
  1367.           HC := clLime;
  1368.           SC := clMaroon;
  1369.           TC := clBlack;
  1370.         end
  1371.         else
  1372.         begin { RO }
  1373.           BC := clLime;
  1374.           HC := clWhite;
  1375.           SC := clGreen;
  1376.           TC := clBlack;
  1377.         end;
  1378.       end
  1379.       else
  1380.       begin
  1381.         if AmSystem then
  1382.         begin { System }
  1383.           BC := clRed;
  1384.           HC := clWhite;
  1385.           SC := clMaroon;
  1386.           TC := clBlack;
  1387.         end;
  1388.       end;
  1389.     end;
  1390.   end;
  1391. end;
  1392.  
  1393. { This procedure gets all icons for an given directory, including drives and }
  1394. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  1395. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  1396.             TargetPath  : String );
  1397. var Finished        : Boolean;         { Loop flag              }
  1398.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1399.     TheResult       : Integer;         { return variable        }
  1400.     TempPath        : String;          { path for FF/FN         }
  1401.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1402.     RowCounter    ,                    { position in row of FIP }
  1403.     ColumnCounter   : Integer;         { position in col of FIP }
  1404.     ButtonColor   ,                    { main panel color       }
  1405.     ButtonHLColor ,                    { bright panel color     }
  1406.     ButtonSColor  ,                    { dark panel color       }
  1407.     Textcolor       : TColor;          { label text color       }
  1408.     IsADir ,                           { Variable for file attr }
  1409.     IsAnArchive ,
  1410.     IsAVolumeID,
  1411.     IsAReadOnlyFile,
  1412.     IsAHiddenFile ,
  1413.     IsASystemFile     : Boolean;
  1414.     MaxTextLength     : Integer;       { Used to safely set size}
  1415. begin
  1416.   { hide during refresh }
  1417.   Visible := false;
  1418.   { Delete the current set, if any }
  1419.   ClearTheFIPs;
  1420.   { Get the icon sizes }
  1421.   TheFIP := TFileIconPanel.Create( Self );
  1422.   TheFIP.Parent := Self;
  1423.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  1424.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  1425.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  1426.   TheFIP.Free;
  1427.   TheIconSize := MaxTextLength + 13;
  1428.   TheIconSpacing := TheIconSize + 5;
  1429.   { Set up maximum icons per row based on screen size }
  1430.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  1431.   { Set up the position counters }
  1432.   RowCounter := 1;
  1433.   ColumnCounter := 1;
  1434.   { Get the drives for the current machine }
  1435.   AddDriveIcons( ColumnCounter , RowCounter  );
  1436.   { Set up the initial variables }
  1437.   Finished := false;
  1438.   TempPath := TargetPath + '*.*';
  1439.   { Make the call to FindFirst set to get any file; will return '.' }
  1440.   { so discard it.                                                  }
  1441.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  1442.   { loop through all files in the directory and look for directories }
  1443.   while not Finished do
  1444.   begin
  1445.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1446.     TheResult := FindNext( TheSR );
  1447.     { A -1 result means no more files so exit }
  1448.     if TheResult < 0 then finished := true else
  1449.     begin
  1450.       { Otherwise check for a directory attribute }
  1451.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1452.        faDirectory ) then
  1453.       begin
  1454.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1455.          ButtonHLColor , ButtonSColor , TextColor );
  1456.         { If found create a new FileIconPanel on the imported scrollbox }
  1457.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1458.         TheFIP := TFileIconPanel.Create( Self );
  1459.         TheFIP.Parent := Self;
  1460.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  1461.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  1462.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1463.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1464.         { Increment column counter and move to new row if past limit }
  1465.         ColumnCounter := ColumnCounter + 1;
  1466.         if ColumnCounter > MaxIconsInARow then
  1467.         begin
  1468.           ColumnCounter := 1;
  1469.           RowCounter := RowCounter + 1;
  1470.         end;
  1471.       end;
  1472.     end;
  1473.   end;
  1474.   { Call FindClose for Windows NT/Windows 95 compatibility }
  1475.   FindClose( TheSR );
  1476.   { Set up new initialization variables }
  1477.   Finished := false;
  1478.   TempPath := TargetPath + '*.*';
  1479.   { Make needed call to FindFirst and discard '.' }
  1480.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  1481.   while not Finished do
  1482.   begin
  1483.     { Loop through file again, this time getting only archive files }
  1484.     TheResult := FindNext( TheSR );
  1485.     { Result of -1 indicates no more files }
  1486.     if TheResult < 0 then Finished := true else
  1487.     begin
  1488.       { If faArchive file then add new FileIconPanel }
  1489.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  1490.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  1491.         IsASystemFile );
  1492.       if (( IsAnArchive ) and ( not IsADir )) then
  1493.       begin
  1494.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1495.          ButtonHLColor , ButtonSColor , TextColor );
  1496.         { Initialize new FileIconPanel and call initialize, sending 0 ED }
  1497.         TheFIP := TFileIconPanel.Create( Self );
  1498.         TheFIP.Parent := Self;
  1499.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  1500.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  1501.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1502.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1503.         { Increment column counter and if needed row counter }
  1504.         ColumnCounter := ColumnCounter + 1;
  1505.         if ColumnCounter > MaxIconsInARow then
  1506.         begin
  1507.           ColumnCounter := 1;
  1508.           RowCounter := RowCounter + 1;
  1509.         end;
  1510.       end;
  1511.     end;
  1512.   end;
  1513.   { Call findclose for w95 and exit }
  1514.   FindClose( TheSR );
  1515.   { Reset to visible }
  1516.   Visible := true;
  1517. end;
  1518.  
  1519. { Update method for FIPscrollbox }
  1520. procedure TFileIconPanelScrollBox.Update;
  1521. begin
  1522.   IconsNeedRefreshing := true;
  1523.   { Force a repaint }
  1524.   InvalidateRect( TheStoredHandle , nil , true );
  1525. end;
  1526.  
  1527. { Create method for FIPScrollbox }
  1528. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  1529. begin
  1530.   inherited Create( AOwner );
  1531.   TheFWB := TFileWorkBench.Create( Self );
  1532. end;
  1533.  
  1534. { This function returns the next selected file's name }
  1535. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  1536.                            var CurrentItem : Integer ) : String;
  1537. var TheResult    : String;      { Holds result of function }
  1538.     TheComponent : TComponent;  { Used for typecast        }
  1539.     finished     : boolean;     { Loop control variable    }
  1540.     TheComponentCount : Integer;
  1541. begin
  1542.   TheComponentCount := ComponentCount;
  1543.   { If past end of components exit with no result }
  1544.   if CurrentItem > TheComponentCount then TheResult := '' else
  1545.   begin
  1546.     { Set loop counter and run till find match or run out }
  1547.     finished := false;
  1548.     while not finished do
  1549.     begin
  1550.       { Pull component out of the list and check it }
  1551.       TheComponent := Components[ CurrentItem - 1 ];
  1552.       { Increment counter for later }
  1553.       CurrentItem := CurrentItem + 1;
  1554.       { Do the typecast with AS }
  1555.       with TheComponent as TFileIconPanel do
  1556.       begin
  1557.         { If its selected make sure OK }
  1558.         if Selected then
  1559.         begin
  1560.           { Don't accept backup for this level of operation }
  1561.           if FTheLabel.Caption <> '..' then
  1562.           begin
  1563.             { Otherwise return the name and abort the loop }
  1564.             TheResult := FTheName;
  1565.             finished := true;
  1566.           end;
  1567.         end
  1568.         else
  1569.         begin
  1570.           { Check to see if out of components }
  1571.           if CurrentItem > TheComponentCount then
  1572.           begin
  1573.             { If so signal error and abort }
  1574.             TheResult := '';
  1575.             finished := true;
  1576.           end;
  1577.         end;
  1578.       end;
  1579.     end;
  1580.   end;
  1581.   GetNextSelection := TheResult;
  1582. end;
  1583.  
  1584. { This procedure places a selection of files in the display based on wildcards }
  1585. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  1586.            TheStartingDirectory : String );
  1587. var XCounter ,
  1588.     YCounter   : Integer;
  1589.  
  1590. { This procedure does a recursive file search by first getting all matches (in-}
  1591. { cluding directories) and adding them to the list. Then it checks for ALL the }
  1592. { subdirectories and does the same trick on them til there are no more matches }
  1593. { and no more subdirectories, at which point it exits and recurses back up.    }
  1594. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  1595.                                YCounter : Integer );
  1596.  
  1597. { VITAL!!! These variables MUST be local for recursrion to work! }
  1598. var
  1599.     Finished        : Boolean;         { Loop flag              }
  1600.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1601.     TheResult       : Integer;         { return variable        }
  1602.     TargetPath ,
  1603.     FileMask   ,
  1604.     TheStoredWorkingDirectory ,
  1605.     ModifiedDirectory  : String;       { path for FF/FN         }
  1606.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1607.     ButtonColor   ,                    { main panel color       }
  1608.     ButtonHLColor ,                    { bright panel color     }
  1609.     ButtonSColor  ,                    { dark panel color       }
  1610.     Textcolor       : TColor;          { label text color       }
  1611.  
  1612. begin
  1613.   { Set up the initial variables }
  1614.   Finished := false;
  1615.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1616.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  1617.   FileMask := ExtractFileName( TheWorkingDirectory );
  1618.   { Make the call to FindFirst set to get any file }
  1619.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1620.   if TheResult < 0 then finished := true;
  1621.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  1622.   then begin
  1623.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1624.      faDirectory ) then
  1625.     begin { A directory }
  1626.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1627.        ButtonHLColor , ButtonSColor , TextColor );
  1628.       { If found create a new FileIconPanel on the imported scrollbox }
  1629.       { Note sending 0 ExtraData parameter to indicate file not drive }
  1630.       TheFIP := TFileIconPanel.Create( Self );
  1631.       TheFIP.Parent := Self;
  1632.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1633.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1634.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  1635.          + TheSr.Name , 'MS Serif' , [] , 0 );
  1636.       { Increment column counter and move to new row if past limit }
  1637.       XCounter := XCounter + 1;
  1638.       if XCounter > MaxIconsInARow then
  1639.       begin
  1640.         XCounter := 1;
  1641.         YCounter := YCounter + 1;
  1642.       end;
  1643.     end
  1644.     else
  1645.     begin { A File }
  1646.       { Set up the default color scheme for files }
  1647.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1648.        ButtonHLColor , ButtonSColor , TextColor );
  1649.       { If found create a new FileIconPanel on the imported scrollbox }
  1650.       { Note sending 0 ExtraData parameter to indicate file not drive }
  1651.       TheFIP := TFileIconPanel.Create( Self );
  1652.       TheFIP.Parent := Self;
  1653.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1654.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  1655.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  1656.          + TheSr.Name , 'MS Serif' , [] , 0 );
  1657.       { Increment column counter and move to new row if past limit }
  1658.       XCounter := XCounter + 1;
  1659.       if XCounter > MaxIconsInARow then
  1660.       begin
  1661.         XCounter := 1;
  1662.         YCounter := YCounter + 1;
  1663.       end;
  1664.     end;
  1665.   end;
  1666.   { loop through all files in the directory and look for matches }
  1667.   while not Finished do
  1668.   begin
  1669.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1670.     TheResult := FindNext( TheSR );
  1671.     { A -1 result means no more files so exit }
  1672.     if TheResult < 0 then finished := true else
  1673.     begin
  1674.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  1675.        faDirectory ) then
  1676.       begin { A directory }
  1677.         { Set up the blue color scheme for directories }
  1678.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1679.          ButtonHLColor , ButtonSColor , TextColor );
  1680.         { If found create a new FileIconPanel on the imported scrollbox }
  1681.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1682.         TheFIP := TFileIconPanel.Create( Self );
  1683.         TheFIP.Parent := Self;
  1684.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1685.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1686.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1687.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1688.         { Increment column counter and move to new row if past limit }
  1689.         XCounter := XCounter + 1;
  1690.         if XCounter > MaxIconsInARow then
  1691.         begin
  1692.           XCounter := 1;
  1693.           YCounter := YCounter + 1;
  1694.         end;
  1695.       end
  1696.       else
  1697.       begin { A File }
  1698.         { Set up the default color scheme for files }
  1699.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  1700.          ButtonHLColor , ButtonSColor , TextColor );
  1701.         { If found create a new FileIconPanel on the imported scrollbox }
  1702.         { Note sending 0 ExtraData parameter to indicate file not drive }
  1703.         TheFIP := TFileIconPanel.Create( Self );
  1704.         TheFIP.Parent := Self;
  1705.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  1706.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  1707.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  1708.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  1709.         { Increment column counter and move to new row if past limit }
  1710.         XCounter := XCounter + 1;
  1711.         if XCounter > MaxIconsInARow then
  1712.         begin
  1713.           XCounter := 1;
  1714.           YCounter := YCounter + 1;
  1715.         end;
  1716.       end;
  1717.     end;
  1718.   end;
  1719.   { Call FindClose for Windows NT/Windows 95 compatibility }
  1720.   FindClose( TheSR );
  1721.   { Set up the variables to do recursive calls on all directories}
  1722.   Finished := false;
  1723.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  1724.   { Make the call to FindFirst set to get any file, ignore result }
  1725.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1726.   while not Finished do
  1727.   begin
  1728.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1729.     TheResult := FindNext( TheSR );
  1730.     { A -1 result means no more files so exit }
  1731.     if TheResult < 0 then finished := true
  1732.     else
  1733.     begin
  1734.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1735.       begin
  1736.         { Do second check due to bug in FindNext }
  1737.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1738.         = faDirectory ) then
  1739.         begin
  1740.           { Set up modified directory to recurse into }
  1741.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  1742.            TheSR.Name + '\' + FileMask;
  1743.           { Perform the recursion }
  1744.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  1745.         end;
  1746.       end;
  1747.     end;
  1748.   end;
  1749. end;
  1750.  
  1751. begin
  1752.   { Keep the scrollbox from updating during refresh }
  1753.   Visible := false;
  1754.   { Make the clear call }
  1755.   ClearTheFIPs;
  1756.   XCounter := 1;
  1757.   YCounter := 1;
  1758.   { Get the drives for the current machine }
  1759.   AddDriveIcons( XCounter , YCounter );
  1760.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  1761.   { Make the scrollbox visible again }
  1762.   Visible := true;
  1763. end;
  1764.  
  1765. end.
  1766.